home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / misc / math / number.lha / number / readme < prev    next >
Encoding:
Text File  |  1988-02-02  |  6.1 KB  |  211 lines

  1.     ::::    Description    ::::
  2.  
  3. This version of number was inspired from the standard
  4. version in /usr/games, but with a big difference:  It
  5. knows how to count in a *lot* of languages, and can
  6. be taught almost anything that it doesn't already know.
  7. The information on how to count in a given language
  8. is given in a grammar, written in a meta-language described
  9. a little later.  Grammars exist, as of this moment, for:
  10.  
  11. Cantonese        French        Japanese    Spanish
  12. Chinese (Mandarin)    Gaellic (Irish)    Malinke        Susu
  13. English            German        Pular        Vietnamese
  14. Esperanto        Italian        Romanian
  15.  
  16. It takes about twenty minutes with a native speaker to
  17. write a grammar, once you understand how to do so.  Instructions
  18. on how to write a grammar are included at the end of this
  19. file.  It is also highly recommended that you study some
  20. of the existing grammars before attempting your own.
  21.  
  22.     ::::    Installation    ::::
  23.  
  24. - Make a directory for this package, and cd to it.
  25. - Run 'sh' on the file that you put this shell archive
  26.   in in order to extract all of the files in it.
  27. - Edit the Makefile to indicate where you want the
  28.   executable, and the grammar files to be kept.
  29.  
  30. ** Important: THIS MUST BE DONE BEFORE YOU COMPILE NUMBER!
  31.  
  32. - Type 'make install'
  33.  
  34.     ::::    Adding languages    ::::
  35.  
  36. ** Note:  If all you want to do is use number, you can skip the
  37.       rest of this file.
  38.  
  39. The grammar files used by number contain rules that
  40. number uses to translate numbers into words.  The
  41. rules are generally of the form:
  42.  
  43. n    rules
  44.  
  45. where 'n' is the "base" number, separated by a single tab from
  46. the rule per se.  The rules must be in ascending order of
  47. base number.  The basic algorithm that number uses to
  48. translate a number to words is to find the rule with
  49. the largest base that is smaller than the number, and
  50. evaluate the rule for that base, given the number.  For
  51. example, one might have the rule:
  52.  
  53. 5    "five"
  54.  
  55. which, if the number being translated were 5, would cause
  56. the rule "five" to be evaluated.  In this case, the rule
  57. is a simple string, which would be printed.  Rules may
  58. contain:
  59.  
  60. - Strings, delimited by double quotes, which are simply printed.
  61. - Spaces, which are printed as well.
  62. - A number, which causes the number to be spelled.
  63. - The following special characters, with the meanings:
  64.   /  Spell the number divided by the base.
  65.   %  Spell the number modulus the base.
  66. - A conditional, described below.
  67. - A single character macro.
  68. - A comma, which functions as a no-op.
  69.  
  70. In addition, grammars contain macro definitions, and may
  71. contain lines of comments, which have a '#' in the first
  72. column.  Rules may be continued across multiple lines by
  73. terminating the line with a '\'.  The next line must
  74. begin with a tab character.
  75.  
  76. Conditionals have the following syntax:
  77.  
  78. (L C R    rule)
  79.  
  80. with a tab separating the 'R' from the rule.  L and R
  81. are either numbers, or one of the characters:
  82.  
  83. /    Number divided by base.
  84. %    Number modulus base.
  85. B    Base.
  86. #    Number.
  87. L    Recursion level.
  88.  
  89. C is one of '<', '>', '=' or '~', meaning less than,
  90. greater than, equal to, or not equal to, respectively.
  91. The following (common) rule, taken from the grammar
  92. for Esperanto, expresses the fact that for units
  93. of 10, the number divided by 10 is only added before
  94. the word for 10 if is greater than 1:
  95.  
  96. 10    (/ > 1    /)"dek" %
  97.  
  98. Thus, if 23 were being evaluated, the conditional would
  99. check to see if 23 / 10 is greater than 1, and, since it
  100. is, evaluate the rule '/' causing 2 to be spelled.  Given
  101. the following grammar:
  102.  
  103. 0    "zero"
  104. 1    "unu"
  105. 2    "du"
  106. 3    "tri"
  107. 4    "kvar"
  108. 5    "kvin"
  109. 6    "ses"
  110. 7    "sep"
  111. 8    "ok"
  112. 9    "na[bre]u"
  113. 10    (/ > 1    /)"dek" %
  114. 100    (/ > 1    /) "cent" %
  115.  
  116. and the number 23, the following would happen:
  117.  
  118. - Select rule for base 10, number 23, since 10 is the largest
  119.   base that is smaller than 23.
  120.   - Evaluate the conditional '(/ > 1    /)'.
  121.     - Evaluate / -> 23 / 10 -> 2.
  122.     - Evaluate 2 > 1 -> TRUE.
  123.     - Evaluate / -> 23 / 10 -> 2.
  124.       - Evaluate rule for base 2, number 2.
  125.     - Print "du".
  126.   - Print "dek".
  127.   - Print " ".
  128.   - Evaluate % -> 23 % 10 -> 3.
  129.     - Evaluate rule for base 3, number 3.
  130.       - Print "tri"
  131.  
  132. The net result is that "dudek tri" is printed.
  133.  
  134.     ::::    Macros    ::::
  135.  
  136. A macro is defined by the following syntax:
  137.  
  138. /    c    rule
  139.  
  140. where c is any letter except L and B.  (Other characters
  141. are allowed as well, but don't bump into special characters...)
  142. In the grammar given above, for Esperanto, we could have
  143. used a macro to simplify the rules for 10 and 100, thus:
  144.  
  145. /    d    (/ > 1    /)
  146. 10    d"dek" %
  147. 100    d "cent" %
  148.  
  149. The following is about the most complicated piece of
  150. code in a grammar, and illustrates most of the features
  151. of the grammar metalanguage.
  152.  
  153. 10    (/ > 1    /) "m'u~'"(/ = 1    "[`]")"'o~'i" a
  154. /    a    (/ > 1    (% = 1    "m[^']ot")(% > 1    c))(/ = 1    c)
  155. /    c    (% = 5    "l[)]am")(% ~ 5    %)
  156. 100    ...
  157.  
  158. It expresses the following:
  159.  
  160. - For any number greater than or equal to 10, but less
  161.   than 100, first spell the number divided by ten, if
  162.   the quotient is greater than one.
  163. - Print the string "m'u~'".
  164. - If the quotient is 1, then print the string "[`]".
  165. - Print the string "'o~'i".
  166. - Expanding the macro 'a', if the quotient is greater
  167.   than 1:
  168.   - If the number modulus the base is 1, print the string "m[^']ot".
  169.   - If the modulus is greater than 1, expanding macro c:
  170.     - If the modulus is 5, print "l[)]am".
  171.     - If the modulus is not 5, evaluate the modulus.
  172. - If the quotient is 1, expanding macro c:
  173.   - If the modulus is 5, print "l[)]am".
  174.   - If the modulus is not 5, evaluate the modulus.
  175.  
  176. The essence of all of this is that if, in Vietnamese, something
  177. comes before the word "m'u~'[`]'o~'i", which means 10, it
  178. loses its tone ("[`]").  Further, the word for 1 (normally
  179. "m[^.]ot" changes its tone in some circumstances, and the
  180. word for 5 ("n[)]am") changes its initial letter to an "l"
  181. in still other situations.  Whew.
  182.  
  183. Macros can be handy for making very short rules.  For example,
  184. in German, 30, 40, etc. are spelled by adding the letters "zig"
  185. to the word for the number divided by 10.  Thus, with the
  186. following macro:
  187.  
  188. /    z    "zig"
  189.  
  190. the rule for 30 can be reduced from:
  191.  
  192. 30    "dreizig"
  193.  
  194. to:
  195.  
  196. 30    3z
  197.  
  198.     ::::    Conclusion    ::::
  199.  
  200. If you write any grammars, I'd greatly appreciate having
  201. them.  My permanent net address is:
  202.  
  203.     scott@cerberus.uchicago.edu
  204.  
  205. USnail address:
  206.  
  207.     Scott Deerwester
  208.     1100 E. 57th, GLS
  209.     University of Chicago
  210.     Chicago, Illinois 60637
  211.